#include "Characters/Character.h"
#include "Characters/Barbarian.h"
#include "Characters/Paladin.h"
#include "Characters/Wizard.h"
#include "Util.h"
#include <string>
#include "CharCreate.h"


std::vector<cmdalt> get_gender_alternatives(){
		std::vector<cmdalt> alternatives;
	{
		// help
		cmdalt alt;
		alt.first = "help";
		alt.second = {};
		alternatives.push_back(alt);
	}
	{
		// male
		cmdalt alt;
		alt.first = "male";
		alt.second = {};
		alternatives.push_back(alt);
	}
	{
		// female
		cmdalt alt;
		alt.first = "female";
		alt.second = {};
		alternatives.push_back(alt);
	}
	
	return alternatives;
}


Character * createCharacter(){
	while(true){
		std::vector<std::string> input = read(get_gender_alternatives(), "Do you want to play as male of female? (help for options)");
		if(input[0].compare("help") == 0){
			printAlternatives(get_gender_alternatives());
		}
		if(input[0].compare("male") == 0){
			return chooseClass(true);
		}
		if(input[0].compare("female") == 0){
			return chooseClass(false);
		}
	}
}

std::vector<cmdalt> get_class_alternatives(){
		std::vector<cmdalt> alternatives;
	{
		// help
		cmdalt alt;
		alt.first = "help";
		alt.second = {};
		alternatives.push_back(alt);
	}
	{
		// male
		cmdalt alt;
		alt.first = "barbarian";
		alt.second = {};
		alternatives.push_back(alt);
	}
	{
		// female
		cmdalt alt;
		alt.first = "paladin";
		alt.second = {};
		alternatives.push_back(alt);
	}
	{
		// female
		cmdalt alt;
		alt.first = "wizard";
		alt.second = {};
		alternatives.push_back(alt);
	}
	
	return alternatives;
}

Character * chooseClass(bool male){
	while(true){
		std::vector<std::string> input = read(get_class_alternatives(), "Choose a class: barbarian, paladin or wizard (help for options)");
		if(input[0].compare("help") == 0){
			printAlternatives(get_class_alternatives());
		}
		if(input[0].compare("barbarian") == 0){
			return chooseRace(male,"barbarian");
		}
		if(input[0].compare("paladin") == 0){
			return chooseRace(male, "paladin");
		}
		if(input[0].compare("wizard") == 0){
			return chooseRace(male, "wizard");
		}
	}
}

std::vector<cmdalt> get_race_alternatives(){
		std::vector<cmdalt> alternatives;
	{
		// help
		cmdalt alt;
		alt.first = "help";
		alt.second = {};
		alternatives.push_back(alt);
	}
	{
		// male
		cmdalt alt;
		alt.first = "choose";
		alt.second = {"human", "orc", "troll", "elf", "dwarf", "seacreature", "werebear", "dragon", "gnome", "giant"};
		alternatives.push_back(alt);
	}
	
	return alternatives;
}


Character * chooseRace(bool male, std::string klass){
	while(true){
		std::vector<std::string> input = read(get_race_alternatives(), "Choose a race (help for options)");
		if(input[0].compare("help") == 0){
			printAlternatives(get_race_alternatives());
		}
		if(input[0].compare("choose") == 0){
			return choosePitch(male, klass, input[1]);
		}
	}
}

std::vector<cmdalt> get_pitch_alternatives(){
		std::vector<cmdalt> alternatives;
	{
		// help
		cmdalt alt;
		alt.first = "help";
		alt.second = {};
		alternatives.push_back(alt);
	}
	{
		// test
		cmdalt alt;
		alt.first = "test";
		alt.second = { "0", "10", "20", "30", "40", "50", "60", "70", "80", "90", "100"};
		alternatives.push_back(alt);
	}
	{
		// choose
		cmdalt alt;
		alt.first = "choose";
		alt.second = { "0", "10", "20", "30", "40", "50", "60", "70", "80", "90", "100"};
		alternatives.push_back(alt);
	}
	return alternatives;
}
Character * choosePitch(bool male, std::string klass, std::string race){
	while(true){
		std::vector<std::string> input = read(get_pitch_alternatives(), "Choose your voice (help for options)");
		if(input[0].compare("help") == 0){
			printAlternatives(get_pitch_alternatives());
		}
		if(input[0].compare("test") == 0){
			std::string test_string = "testing voice";
			speak(test_string, male, atoi(input[1].c_str()));
		}
		if(input[0].compare("choose") == 0){
			std::string say = "You have chosen to be a ";
			if(male){
				say += "male ";
			}
			else{
				say += "female ";
			}
			say += race;
			say+= " ";
			say += klass;
			speak(say);
			Character * player;
			if(klass.compare("barbarian") == 0){
				player = new Barbarian("You", race, male, false, Progress::ach(NONE, 0), atoi(input[1].c_str()));
			}
			if(klass.compare("paladin") == 0){
				player = new Paladin("You", race, male, false,Progress::ach(NONE, 0), atoi(input[1].c_str()));
			}
			if(klass.compare("wizard") == 0){
				player = new Wizard("You", race, male, false,Progress::ach(NONE, 0), atoi(input[1].c_str()));
			}
			return setTrashTalk(player);
		}
	}
}

std::vector<cmdalt> get_trash_alternatives(){
		std::vector<cmdalt> alternatives;
	{
		// help
		cmdalt alt;
		alt.first = "help";
		alt.second = {};
		alternatives.push_back(alt);
	}
	{
		// yes
		cmdalt alt;
		alt.first = "yes";
		alt.second = {};
		alternatives.push_back(alt);
	}
	{
		// choose
		cmdalt alt;
		alt.first = "no";
		alt.second = {};
		alternatives.push_back(alt);
	}
	return alternatives;
}

Character * setTrashTalk(Character * player){
	std::vector<std::string> trashTalk;
	while(true){
		std::vector<std::string> input;
		if(trashTalk.size() == 0){
			input = read(get_trash_alternatives(), "Do you want to set custom trashtalk? (help for options)");
		}
		else{
			input = read(get_trash_alternatives(), "Do you want to add another custom trashtalk? (help for options)");
		}
		if(input[0].compare("help") == 0){
			printAlternatives(get_trash_alternatives());
		}
		if(input[0].compare("no" )== 0){
			if(trashTalk.size() > 0){
					speak("Custom trashtalks added");
					player->setTrashTalk(trashTalk);
			}
			return player;
		}
		if(input[0].compare("yes") == 0){
			speak("Input a new trash talk");
			std::string line;
			getline(std::cin, line);
			if(!line.empty()){
				trashTalk.push_back(line); 
			}
		}
	}

}




